<template>
  <div class="categories">
    <div class="gradient-right"></div>
    <!-- 右侧渐变 -->
    <div class="scroll-container">
      <template v-for="(item, index) in homeCategoryList" :key="item.id">
        <div class="item">
          <img :src="item.pictureUrl" alt="" />
          <span>{{ item.title }}</span>
        </div>
      </template>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import useHomeStore from '@/stores/modules/home'
import { storeToRefs } from 'pinia'

const homeStore = useHomeStore()
const page = ref(1)

onMounted(() => {
  homeStore.getHomeCategory(page.value)
})

const { homeCategoryList } = storeToRefs(homeStore)
</script>

<style lang="scss" scoped>
.categories {
  position: relative; /* 确保子元素可以相对定位 */
  display: flex;
  margin: 10px 0px;
  overflow: hidden; /* 防止内容溢出 */

  .scroll-container {
    display: flex;
    margin: 10px 0px;
    justify-content: space-around;
    overflow-x: auto;
    -ms-overflow-style: none; /* 隐藏Internet Explorer和Edge的滚动条 */
    scrollbar-width: none; /* 隐藏Firefox的滚动条 */

    &::-webkit-scrollbar {
      display: none; /* 针对WebKit浏览器（如Chrome, Safari）隐藏滚动条 */
    }

    .item {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin: 5px;

      img {
        width: 32px;
        height: 32px;
      }

      span {
        text-wrap: nowrap;
      }
    }
  }

  /* 右侧渐变 */
  .gradient-right {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 50px; /* 根据需要调整宽度 */
    background: linear-gradient(to left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0));
    pointer-events: none; /* 确保渐变层不会影响点击或触摸事件 */
  }
}
</style>
